<template>
	<!-- 修改 查看日常报销单 -->
	<view class="container"
		style="width: 100%;box-sizing: border-box;background-color: #fff;padding:20rpx 20rpx 20rpx 20rpx">
		<uni-forms ref="form" :modelValue="entity" label-width="100px">
			<view>
				<view>
					<uni-section title="基本信息" type="line"></uni-section>
				</view>
				<uni-forms-item label="申请日期:" :rules="$rules.handle.ApplicationDate" required name="ApplicationDate">
					<view @click="timeClick('ApplicationDate')">
						<uni-easyinput v-model="entity.ApplicationDate" :disabled="true" />
					</view>
				</uni-forms-item>
				<uni-forms-item label="公司名称:" :rules="$rules.handle.CompanyName" required name="CompanyName">
					<view @click="CustomerChoice('CompanyName')">
						<uni-easyinput v-model="entity.CompanyName" :suffixIcon="disabled ?'': 'compose'"
							:disabled="true" />
					</view>
				</uni-forms-item>
				<uni-forms-item label="部门名称:" :rules="$rules.handle.DeptName" required name="DeptName">
					<view @click="CustomerChoice('DeptName')">
						<uni-easyinput v-model="entity.DeptName" :suffixIcon="disabled ?'': 'compose'"
							:disabled="disabledDeptName" />
					</view>
				</uni-forms-item>
				<uni-forms-item label="报销人姓名:" :rules="$rules.handle.ApplicationPerson" required
					name="ApplicationPerson">
					<view>
						<uni-easyinput v-model="entity.ApplicationPerson" :disabled="disabled" />
					</view>
				</uni-forms-item>
				<uni-forms-item label="报销单号:" name="ReimburseCode">
					<view>
						<uni-easyinput v-model="entity.ReimburseCode" :disabled="true" />
					</view>
				</uni-forms-item>
				<uni-forms-item label="票面总金额:" name="FaceAmount">
					<view>
						<uni-easyinput v-model="entity.FaceAmount" :disabled="true" />
					</view>
				</uni-forms-item>
				<uni-forms-item label="报销总金额:" name="ReimburseAmount">
					<view>
						<uni-easyinput v-model="entity.ReimburseAmount" :disabled="true" />
					</view>
				</uni-forms-item>
				<uni-forms-item label="备注:">
					<view>
						<uni-easyinput v-model="entity.Abstract" type="textarea" maxlength="300" :disabled="disabled" />
					</view>
				</uni-forms-item>


			</view>
			<view class="flex Acenter Jbetween">
				<uni-section title="费用明细" type="line"></uni-section>
				<view v-if="!disabled" class="flex Acenter Jbetween" @click="AddDetailClick">
					<u-icon name="plus-circle-fill" color="#2979ff" size="45"></u-icon>
					<text style="color:#2979ff;font-weight:bold;padding-left: 10rpx;">添加明细</text>

				</view>
			</view>
			<view class="scrollBox">
				<scroll-view style="width: 100%;height: 100%;" scroll-y="true">
					<view style="padding-bottom: 50px;">
						<view class=" " v-for="(item, index) in detailData" :key="item.Id"
							@click="handleDetail(entity, item, index)" style=" width: 100%; 
					      margin: 0 auto;
					      box-shadow: 3px 4px 16px 0px #6b6b6a;
					      margin-top: 40rpx;
					      margin-bottom: 10px;
					      background-color: #ffffff;
					      border-radius: 10rpx;
					     padding: 20rpx;
					    ">
							<view class="left" style="font-size: 14px; color: #000">
								客户:<span class="font">{{item.CustomerName}}</span>
							</view>
							<view class="flex Jbetween" style="font-size: 14px">
								<span class="font">业务性质: {{ item.ExpenseType || "无" }}</span>
								<span class="font">票据类型: {{ item.BillTypeName || "无" }}</span>
							</view>
							<view class="flex Jbetween" style="font-size: 14px">
								<span class="font">发票分类: {{ item.InvoiceClassificationName || "无" }}</span>
								<span class="font">是否无票支出: {{ item.IsBill ? item.IsBill ==1 ? '是' : "否" : "否"}}</span>
							</view>
							<view class="flex Jbetween" style="font-size: 14px">
								<span class="font">票面金额: {{ item.FaceAmount || "无" }}</span>
								<span class="font">报销金额: {{ item.ReimburseAmount || "无" }}</span>
							</view>
							<view class="flex Jbetween" style="font-size: 14px">
								<span class="font">票据张数: {{ item.BillsNum +"张" }}</span>
							</view>
							<view class="flex Jbetween" style="font-size: 14px">
								<span class="font">摘要: {{ item.ItemAbstract || "无" }}</span>
							</view>
							<!-- 附件 -->
							<view class="flex Jbetween" style="font-size: 14px">
								<span v-if="item.reimburse_Files" class="font">附件 *
									{{item.reimburse_Files.length}}</span>
								<!--暂时不删除 后续根据需求操作 -->
								<!-- <view v-if="item.reimburse_Files.length>0" v-for="(v,i) in item.reimburse_Files"
									:key="i">
									<span class="font">附件: {{ v.FilePath.substring(-10) || "无" }}</span>
								</view> -->
							</view>
							<view v-if="!disabled" class="flex Jend">
								<view @click.stop="handleItemEdit(entity, item, index)" style="
								  width: 15%;
								  border-radius: 5px;
								  line-height: 30px;
								  color: #fff;
								  text-align: center;
								  margin-top: 10rpx;
								  background-color: #2979ff;
								  margin-right: 30rpx;
								">
									修改
								</view>
								<view @click.stop="handelDelete([item.Id], index)" style="
								  width: 15%;
								  border-radius: 5px;
								  line-height: 30px;
								  color: #fff;
								  text-align: center;
								  margin-top: 10rpx;
								  background-color: red;
								">
									删除
								</view>
							</view>
						</view>
						<view style="margin: 50rpx 0;">
							<u-empty v-if="detailData.length==0" text="请添加明细" mode="list"></u-empty>
						</view>
					</view>
				</scroll-view>
			</view>
			<view v-if="options.ActivityName ==='开始'">
				<view class="submitButton" style="display: flex;align-items: center;">
					<u-button type="primary" plain style="font-size: 14px;width: 200rpx;" @click="onSubmit(0)"
						:loading="loading">保存草稿</u-button>
					<u-button type="primary" style="font-size: 14px;width: 200rpx;" @click="onSubmit(1)"
						:disabled="isButtonDisabled" :loading="loading">提交</u-button>
				</view>
			</view>
			<view v-else-if="options.ActivityName === 'null'">
			</view>
			<view v-else>
				<view class="submitButton" style="display: flex;align-items: center;">
					<u-button type="default" plain style="font-size: 14px;width: 200rpx;" @click="urlBack"
						:loading="loading">返回</u-button>
					<u-button type="primary" style="font-size: 14px;width: 200rpx;" @click="onSubmit(2)"
						:loading="loading">审批</u-button>
				</view>
			</view>

		</uni-forms>

		<!-- 审批弹窗 -->
		<uni-popup ref="inputDialog" type="dialog">
			<!-- 后续使用该样式直接打开即可 position: absolute;right: 20rpx;top: 20rpx; color="#909390"-->
			<view style="display: flex;justify-content: flex-end;margin-bottom: 10rpx;">
				<uni-icons type="closeempty" size="30" @click="$refs.inputDialog.close()"></uni-icons>
			</view>
			<uni-popup-dialog cancelText="不同意" confirmText="同意" title="审批意见" type="info" :value="comment"
				@close="dialogInputHandleSubmit(2)" @confirm="dialogInputHandleSubmit(1)" before-close>
				<uni-easyinput type="textarea" v-model="comment" placeholder="请输入审批意见" :adjust-position="false" />
			</uni-popup-dialog>
		</uni-popup>

		<!-- 选择日期 -->
		<u-calendar v-model="isCalendar" :mode="mode" placeholder="请选择日期" @change="timeChangeClick"></u-calendar>
		<!-- 引用公司子组件 -->
		<Company ref="Company" @change="changeHandler" @cancel="$refs.Company.close()" :title="'请选择公司'"></Company>
	</view>
</template>

<script>
	import {
		mapState
	} from "vuex";
	// 引用公司选择子组件
	import Company from '@/components/Company.vue'
	import AddDetail from './AddDetail.vue';
	// 引入公共头部组件
	import {
		//获取公司列表数据
		CompanyDataList,
		// 获取部门下拉列表
		DepartmentList,
		// 获取日常报销单主表详情
		Reimburse_Daily_MainGetTheData,
		// 日常子表刪除
		Reimburse_Daily_ItemDeleteData,
		// 日常审批提交
		Ai_WorkitemDailyApproved,
		// 日常新建保存草稿 提交
		Reimburse_Daily_MainSaveData
	} from "@/api/interface.js";
	export default {
		components: {
			// 公司组件
			Company,
			// 新建明细
			AddDetail,

		},
		data() {
			return {
				// 是否允许提交按钮
				isButtonDisabled: false,
				// 标签栏点击的是我的样品还是反馈
				// currentIndex: 0,
				// tabsList: ['表单内容', '我发起的'],
				// 审批意见
				comment: '',
				// 禁用
				disabled: false,
				// 禁用部门名称
				disabledDeptName: false,
				// 加载
				loading: false,
				entity: {},
				// 是否显示日期弹窗
				isCalendar: false,
				// 日期选择
				mode: 'date',
				// 是否展示公司选择底部弹窗组件
				showPopup: false,
				// 底部弹窗列表数据
				columns: [],
				// 点击弹出底部弹窗的字段类型
				dataType: "",
				// 明细表
				detailData: [{
					CustomName: '客户名称',
					ExpenseType: '业务性质',
					BillType: '票据类型',
					InvoiceClassification: '发票分类',
					ItemAbstract: '摘要',
					FaceAmount: '票面金额',
					ReimburseAmount: '报销金额',
					BillsNum: 12,
					IsNoTicket: '是否无票支出'
				}],
				options: {},
				// 记录子表的数组下标
				detailDataIndex: 0,


			}
		},
		computed: {
			...mapState(["UserInfo", "BillTypeOptions", "ExpenseTypeOptions", "InvoiceClassificationOptions",
				"CompayListOptions", "CustomerInfoOptions"
			]),
		},
		onLoad(options) {
			this.options = options
			uni.setNavigationBarTitle({
				title: '修改日常报销单'
			})
			if (options.disabled === "true") {
				this.disabled = true
				uni.setNavigationBarTitle({
					title: '日常报销单详情'
				})
			} else {
				this.disabled = false
			}
			this.disabledDeptName = true
			// 获取日常报销单主表详情
			this.getReimburse_Daily_MainGetTheData(options.ApprovalFormId)
		},
		methods: {
			// 求和函数
			sumObjects(arr, key) {
				return arr.reduce((sum, current) => sum + parseFloat(current[key] || 0), 0)
			},
			// 计算票面总金额和报销总金额
			getTotalAmount() {
				// 计算票面总金额
				const newFaceAmount = this.sumObjects(this.detailData, 'FaceAmount')
				// 计算报销总金额
				const newReimburseAmount = this.sumObjects(this.detailData, 'ReimburseAmount')
				// 计算差额
				const totalDifference = newFaceAmount - newReimburseAmount

				// 票面总金额和报销总金额赋值entity
				this.entity.FaceAmount = newFaceAmount
				this.entity.ReimburseAmount = newReimburseAmount
				// 差额赋值
				this.entity.Difference = totalDifference
				// 应付金额赋值
				this.entity.PayableAmount = newReimburseAmount
				// 应付金额赋值后实时更新大写
				const value = this.$utils.transformToUppercase(this.entity.PayableAmount)
				// 大写赋值
				this.entity.Capitalization = value
			},
			mergeObjects(b, a) {
				return {
					...a,
					...b,

				};
			},
			// 日期时间选择
			timeClick(type) {
				if (this.disabled) return
				this.isCalendar = true
			},
			// 日期选择calendarChange
			timeChangeClick(event) {
				// *************注意  存储必须用set赋值  否则校验不通过   ************************************
				this.$set(this.entity, "ApplicationDate", event.result);
				// *************注意  存储必须用set赋值  否则校验不通过   ************************************
			},
			// 返回
			urlBack() {
				uni.navigateBack()
			},
			// 添加明细
			AddDetailClick() {
				uni.navigateTo({
					url: "/pages/Approval/AddDetail"
				})
				// this.$refs.AddDetail.openForm()
			},

			// 编辑条件修改子表
			setDetailData(type, data) {
				if (type === 'add') {
					// 新增
					this.detailData.push(data)
				} else {

					// 编辑
					let newDetailData = this.detailData
					newDetailData.forEach((item, index) => {
						if (item.Id && item.Id === data.Id) {
							newDetailData[index] = data
						} else {
							// 替换数组里对应对象
							this.detailData.splice(this.detailDataIndex, 1, data)
						}
					})
				}
				// 计算票面总金额和报销总金额
				this.getTotalAmount()
				this.$forceUpdate()
			},
			// 子表编辑
			handleItemEdit(entity, item, index) {
				this.detailDataIndex = index
				let data = {
					entity: entity,
					item: item
				}
				if (this.options.TemplateName === '日常报销单') {
					uni.navigateTo({
						url: "/pages/Approval/EditDetail?data=" + JSON.stringify(data)
					})
				}

			},
			// 查看
			handleDetail(entity, item, index) {
				// 说明是详情 只做查看逻辑
				let data = {
					entity: entity,
					item: item
				}
				if (this.options.ActivityName === 'null' || entity.Satus == 1) {
					//跳转差旅报销明细编辑
					uni.navigateTo({
						url: "/pages/Approval/EditDetail?data=" + JSON.stringify(data) + '&type=查看'
					})
				}

			},
			// 子表删除
			handelDelete(rowId, index) {
				var that = this
				this.$utils.showConfirm({
					content: '确定要删除吗',
					confirmText: "删除",
					confirmColor: "#D1100b"
				}).then(res => {
					if (res.confirm) {
						if (rowId[0] == undefined) {
							// 说明灭有id 直接删除
							// 视图删除
							that.detailData.splice(index, 1)
							return
						}
						uni.showLoading({
							title: '删除中'
						})
						this.loading = true
						Reimburse_Daily_ItemDeleteData(rowId).then(resJson => {
							if (resJson.Success) {
								that.$sucessToast('已删除')
								setTimeout(function() {
									that.loading = false
									uni.hideLoading()
								}, 2500)
								// 视图删除
								that.detailData.splice(index, 1)

							} else {
								that.$errorToast(resJson.Msg);
								setTimeout(function() {
									that.loading = false
									uni.hideLoading()
								}, 2500)
							}
						})
					} else {
						this.loading = false;
					}
				})
			},

			// 处理业务性质回显函数
			generateCArray(a, b) {
				return a.map((item, index) => ({
					text: item,
					value: b[index]
				}));
			},
			// 处理业务性质回显
			getExpenseTypeName(entity) {
				let ExpenseTypeNameArr = entity.ExpenseTypeName.split('/')
				let ExpenseTypeArr = entity.ExpenseType.split('/')
				let newExpenseTypeName = this.generateCArray(ExpenseTypeNameArr, ExpenseTypeArr)
				// 回显业务性质
				this.$set(this.entity, 'ExpenseTypeName', newExpenseTypeName)
			},

			// 获取日常报销单主表详情
			getReimburse_Daily_MainGetTheData(id) {
				uni.showLoading({
					title: '加载中'
				})
				Reimburse_Daily_MainGetTheData({
					id: id
				}).then(resJson => {

					if (resJson.Success) {
						uni.hideLoading()
						this.entity = resJson.Data
						// 获取部门下拉列表
						this.getDepartmentList(this.entity.CompanyId, '详情')
						// 日期格式化
						this.entity.ApplicationDate = this.$moment(resJson.Data.ApplicationDate).format(
							"YYYY-MM-DD")

						// /公司下拉回显
						this.entity.CompanyName = this.CompayListOptions.filter(item => item.value === resJson.Data
							.CompanyId)[0].text
						if (resJson.Data.reimburse_Daily_ItemDTOs && resJson.Data.reimburse_Daily_ItemDTOs.length >
							0) {
							resJson.Data.reimburse_Daily_ItemDTOs.forEach(item => {
								// 处理附件的名称
								if (item.reimburse_Files) {
									let arr = []
									item.reimburse_Files.forEach(v => {
										if (v.FilePath) {
											v.FileName = v.FilePath.split('/').pop()
											let obj = {
												fileEntity: v
											}
											arr.push(obj)
											item.reimburse_Files = arr
										}

									})
								}
								// 处理是否无票支出回显
								if (item.IsBill) {
									if (item.IsBill == true) {
										item['IsBill'] = 1
									} else {
										item['IsBill'] = 0
									}
								} else {
									item['IsBill'] = 0
								}
								// 业务性质回显
								if (item.ExpenseType) {
									let ExpenseTypeArr = item.ExpenseType.split('/')
									let ExpenseTypeIdArr = item.ExpenseTypeId.split('/')
									let arr = [{
											text: ExpenseTypeArr[0],
											value: ExpenseTypeIdArr[0]
										},
										{
											text: ExpenseTypeArr[1],
											value: ExpenseTypeIdArr[1]
										}
									]
									item['ExpenseTypeName'] = arr
									console.log('业务性质寻喊回显了', item, arr)
								}
								if (item.BillType) {
									// // 票据类型回显
									item.BillTypeName = this.BillTypeOptions.filter(v => v.value === item
											.BillType)[0] ?
										this.BillTypeOptions.filter(v => v.value === item.BillType)[0]
										.text :
										item.BillType
								}
								if (item.InvoiceClassification) {
									// 发票分类类型回显
									item.InvoiceClassificationName = this.InvoiceClassificationOptions
										.filter(
											v => v.value === item.InvoiceClassification)[0] ?
										this.InvoiceClassificationOptions.filter(v => v.value === item
											.InvoiceClassification)[0].text : item.InvoiceClassification
								}
								if (item.CustomId) {
									let CustomIdArr = item.CustomId.split(',')
									let CustomNameArr = item.CustomName.split(',')
									let CustomerNameOptions = []
									CustomIdArr.forEach((v, i) => {
										CustomNameArr.forEach((m, k) => {
											if (i == k) {
												let obj = {
													Id: v,
													cCusName: m
												}
												CustomerNameOptions.push(obj)
											}

										})
									})
									item['CustomerNameOptions'] = CustomerNameOptions
									item['CustomerName'] = item.CustomName
									console.log('客户回显', item)
								}
							})


						}
						// 子表回显
						this.detailData = resJson.Data.reimburse_Daily_ItemDTOs
					}
				})

			},
			// 公司选择
			CustomerChoice(value) { // 获取公司下拉列表数据
				if (this.disabled) return
				this.dataType = ""
				this.dataType = value
				// 判断公司名称是否为空  再点击部门选择的时候
				if (value === 'DeptName') {
					if (!this.entity.CompanyName) {
						// 如果没有公司先禁用部门名称
						this.disabledDeptName = true
						this.$errorToast('请先选择公司')
						return
					}
				}
				if (value === 'CompanyName') {
					// 获取公司下拉列表数据
					this.getCompanyDataList()
				} else {
					if (this.entity.CompanyId) {
						// 获取部门下拉列表
						this.getDepartmentList(this.entity.CompanyId)
					}
				}


			},
			// 获取部门列表数据
			// 底部弹窗选中事件
			changeHandler(children) {
				if (children) {
					// 如果选择公司了.打开部门名称
					this.disabledDeptName = false
				}
				// 公司和部门名称id赋值
				if (this.dataType === 'CompanyName') {
					// 重新选择公司名称  初始化部门名称和id
					this.entity.DeptName = ""
					this.entity.DepartmentId = ""
					this.$set(this.entity, "CompanyName", children.label);
					this.$set(this.entity, "CompanyId", children.value);
				} else {
					this.$set(this.entity, "DeptName", children.label);
					this.$set(this.entity, "DepartmentId", children.value);
				}

				this.$forceUpdate()
				// 隐藏底部弹窗
				this.$refs.Company.close()
			},
			//获取公司列表数据
			getCompanyDataList() {
				CompanyDataList({}).then(resJson => {
					if (resJson.Success) {
						this.columns = resJson.Data.map(item => {
							return {
								value: item.Id,
								label: item.title
							}
						})

					}
					this.$refs.Company.open(this.columns)
				})
			},
			// 获取部门下拉列表
			getDepartmentList(CompanyId, type) {
				DepartmentList({
					DeptId: CompanyId
				}).then(resJson => {
					if (resJson.Success) {
						this.columns = resJson.Data.map(item => {
							return {
								value: item.Id,
								label: item.Name
							}
						})

					}
					if (type === '详情') {
						let DeptName = this.columns.filter(item => item.value === this.entity.DepartmentId)[0]
							.label
						this.$set(this.entity, 'DeptName', DeptName)
						this.$forceUpdate()
						return
					}
					this.$refs.Company.open(this.columns)
				})
			},

			// 审批意见 同意  -不同意
			dialogInputHandleSubmit(type) {
				var that = this
				let obj = {}
				if (type == 1) {
					obj.Id = this.options.ApprovalFormId
					obj.comment = this.comment
					obj.flag = true
				} else {
					obj.Id = this.options.ApprovalFormId
					obj.comment = this.comment
					obj.flag = false
				}
				this.loading = true
				uni.showLoading({
					title: '审批中'
				})
				// 日常审批提交
				Ai_WorkitemDailyApproved(obj).then(resJson => {
					if (resJson.Success) {
						this.$sucessToast('审批成功')
						setTimeout(function() {
							that.loading = false
							uni.navigateBack()
							uni.hideLoading()
						}, 2500)

					} else {
						this.$errorToast(resJson.Msg)
						setTimeout(function() {
							that.loading = false
							uni.navigateBack()
							uni.hideLoading()
						}, 2500)
					}

				})
				// 关闭 弹窗
				this.$refs.inputDialog.close()
			},

			// 审批意见弹窗确定
			// dialogInputConfirm(e) {
			// this.$refs.form.validate().then(res => {
			// 	uni.showLoading()
			// 	this.$http('Base_ProjectWork/Base_Project/SaveData', {
			// 		...this.formData,
			// 		ProUserList: this.userList.map(item => {
			// 			return {
			// 				UserId: item.MailUserId,
			// 				UserName: item.Name,
			// 				PhoneNumber: item.Phone,
			// 				CreateTime: item.CreateTime
			// 			}
			// 		})
			// 	}).then(res => {
			// 		uni.hideLoading()
			// 		if (res.Success) {
			// 			this.$refs.inputDialog.close()
			// 			console.log('获取添加成功后的项目结果', res.Data)
			// 			// 更新列表
			// 				this.getDataList()
			// 			uni.navigateTo({
			// 				url: '/pages/List/cPage/projectToPage?obj=' + JSON.stringify(res.Data)
			// 			})

			// 		} else {
			// 			uni.hideLoading()
			// 			uni.showToast({
			// 				icon: 'none',
			// 				title: res.Msg
			// 			})
			// 		}
			// 	})
			// }).catch(err => {
			// 	console.log('表单错误信息：', err);
			// })
			// },

			// 提交
			onSubmit(type) {
				// 点击 1.保存草稿  2  提交
				var that = this
				// 点击的是提交
				if (type == 1) {
					this.isButtonDisabled = true
					this.loading = true
					// 点击的是提交   判断子表是否全部为空  禁用
					if (this.detailData.length == 0) {
						setTimeout(function() {
							that.loading = false
							that.isButtonDisabled = false
						}, 1000)
						this.$errorToast('请添加明细后再提交')
						return
					}

				}
				// 点击的是审批
				if (type == 2) {
					this.comment = ""

					this.$refs.inputDialog.open()
					return
				}

				let newEntity = JSON.parse(JSON.stringify(this.entity))
				// 提交 1  草稿  0
				newEntity['Satus'] = type

				if (newEntity.reimburse_Daily_ItemDTOs) {
					newEntity.reimburse_Daily_ItemDTOs.forEach(item => {
						// 单独处理是否无票支出参数
						if (item.IsBill && (item.IsBill == true || item.IsBill == 1)) {
							item.IsBill = true
						} else {
							item.IsBill = false
						}

						let Upload = []
						let reimburse_Files = []
						if (item.reimburse_Files && item.reimburse_Files.length > 0) {
							item.reimburse_Files.forEach(v => {
								// 如果是新上传的 直接放到Upload里
								if (v.fileEntity.id && !v.invoiceId) {
									delete v.invoiceId
									Upload.push(v)
								}
								// /如果是详情过来的直接push详情
								if (v.fileEntity.Id) {
									reimburse_Files.push(v.fileEntity)
								} else {
									// 否则是新上传的直接取linkurlpush
									let obj = {
										FilePath: v.fileEntity.linkUrl
									}
									reimburse_Files.push(obj)
								}
							})
							item.reimburse_Files = reimburse_Files
							item.Upload = Upload
						}
					})
				}

				// 1.保存草稿  2  提交
				var that = this
				this.$refs.form.validate().then(res => {
					// this.resetFields()
					this.loading = true
					// this.resetFields()
					// 暂时不删除************************************************************8
					// let Upload = this.entity.reimburse_Files.filte(item.fileEntity.id)
					// // 差额
					// newEntity['Difference'] = this.entity.Difference ? this.entity.Difference : 0
					// // 票面金额
					// newEntity['FaceAmount'] = this.entity.FaceAmount ? this.entity.FaceAmount : 0
					// // 应付金额
					// newEntity['PayableAmount'] = this.entity.PayableAmount ? this.entity.PayableAmount : 0
					// // 报销金额
					// newEntity['ReimburseAmount'] = this.entity.ReimburseAmount ? this.entity.ReimburseAmount : 0
					// // 子表明细
					// newEntity['reimburse_Daily_ItemDTOs'] = this.detailData
					// newEntity['CreatorId'] = this.UserInfo.UserInfo.CreatorId
					// // newEntity['CompanyId'] = this.UserInfo.CompanyId
					// newEntity['TemplateId'] = this.options.TemplateId
					// this.$set(this.entity, 'Upload', Upload)
					// this.$set(this.entity, 'reimburse_Files', reimburse_Files)
					// if(newEntity.reimburse_Files && newEntity.reimburse_Files.length>0){
					// 	newEntity.reimburse_Files.forEach(item=>{
					// 		if(item.fileEntity.id){
					// 			Upload.push()
					// 		}
					// 	})
					// }
					uni.showLoading({
						title: '加载中'
					})
					// 点击 1.保存草稿  2  提交

					Reimburse_Daily_MainSaveData(newEntity)
						.then(resJson => {
							if (resJson.Success) {
								that.$sucessToast(type == 0 ? '保存成功' : type == 1 ? '提交成功' : '操作成功')
								setTimeout(function() {
									that.loading = false
									uni.navigateBack()
									uni.hideLoading()

								}, 2500)
							} else {
								that.$errorToast(resJson.Msg);
								setTimeout(function() {
									that.loading = false
									uni.navigateBack()
									uni.hideLoading()
								}, 2500)
							}
						});

				}).catch(err => {
					uni.hideLoading()
					that.loading = false
				})
			}

		}
	}
</script>

<style lang="less" scoped>
	// 覆盖uni-section 的样式uni-section
	::v-deep.uni-section {
		.uni-section-header {
			padding: 24rpx 0 !important;
		}
	}

	/* 设置 label 的样式 */
	::v-deep.uni-forms-item {
		padding-right: 40rpx !important;

		/* 例如，设置 label 的宽度和对齐方式 */
		.uni-forms-item__label {
			display: flex !important;
			justify-content: flex-end !important;
		}
	}

	.container {
		.scrollBox {

			margin-bottom: 130rpx;
			/* #ifdef H5 */
			height: calc(100vh - 360px);
			/* #endif */
			/* #ifdef APP */
			height: calc(100vh - 220px);
			/* #endif */
		}

		/* 适配底部导航栏 */
		.submitButton {
			position: fixed;
			left: 0;
			right: 0;
			bottom: 0;
			height: 150rpx;
			/*暂时发现安卓小屏手机安全区为0 && 不带单位的话padding-bottom会失效，写一个兜底, 并写在最上面；f12发现css样式如果都给height设置样式，会依次往下，用最底下的一个样式，如果最下面的没失效，依次往上查找，所以兜底的写在最上面 */
			height: calc(150rpx + constant(safe-area-inset-bottom));
			/* 直接扩展高度，因为padding-bottom是内边距 */
			height: calc(150rpx + env(safe-area-inset-bottom));
			/* 直接扩展高度 */
			background: #fff;
			box-sizing: border-box;
			padding-bottom: constant(safe-area-inset-bottom);
			/*兼容 iOS<11.2 */
			padding-bottom: env(safe-area-inset-bottom);
			/* 兼容iOS>= 11.2*/
			border-top: 1px solid #e9e9e9;
			padding-left: 15px;
			padding-right: 15px;
		}
	}
</style>